package cn.kgc.interceptor;

import cn.kgc.entity.Emp;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws IOException {
        HttpSession session = request.getSession();
        Emp loginEmp = (Emp) session.getAttribute("loginEmp");

        if (loginEmp == null) {
            response.sendRedirect(request.getContextPath()+"/toLogin");
            return false;
        }
        return true;
    }
}
